use fast_log::{
    consts::LogSize,
    plugin::file_split::RollingType,
    error::LogError,
    wait::FastLogWaitGroup,
};
use crate::basic::util::file;
use log::Level;

pub fn init_log(name: &str, debug: bool, split: bool) -> Result<FastLogWaitGroup, LogError> {
    let level = if debug { Level::Debug } else { Level::Info };
    if split {
        let log_dir_path = format!("logs/{}/", name);
        file::create_path(&log_dir_path);
        fast_log::init_split_log(
            &log_dir_path,
            1024,
            LogSize::MB(1),
            true,
            RollingType::All,
            level,
            None,
            true,
        )
    } else {
        let log_file_path = format!("logs/{}.log", name);
        file::create_path("logs/");
        fast_log::init_log(
            &log_file_path,
            1024, level,
            None, true,
        )
    }
}